#include <stdio.h>
#include <assert.h>
#include <time.h>
#include <math.h>


char* ff(char* str, int s, int n)
{
    char arr[] = "0123456789ABCDEF";
    int a = 0;
    int i = 0;
    if (s < 0)
        str[i++] = '-';
    int m = abs(s);
    while (m)
    {
        a = m % n;
        m = m / n;
        str[i++] = arr[a];
    }
    
     a = 0;

     if (str[a] == '-')
         a = 1;

     str[i--] = '\0';
    while (a < i)
    {
        char tmp = str[i];
        str[i] = str[a];
        str[a] = tmp;
        a++;
        i--;
    }
    return str;
}
int main()
{
    int M;
    int N;
    char* str = 0;
    char arr[50];
    while (scanf("%d%d", &M, &N) != EOF)
    {
        str = ff(arr, M, N);
        printf("%s", str);
        printf("\n");
    }
    return 0;
}